import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import i18n from './lang' // internationalization
import axios from 'axios'

Vue.use(ElementUI, { i18n: (key, value) => i18n.t(key, value) })
Vue.config.productionTip = false
Vue.prototype.$axios = axios
axios.interceptors.request.use(
  function(config) {
    // 在发送请求之前做些什么
    const token = localStorage.getItem('token')
    if (token) {
      config.headers['X-TOKEN'] = localStorage.getItem('token')
      console.log('向header添加了token')
    }
    return config
  }, function(error) {
    // 对请求错误做些什么
    return Promise.reject(error)
  }
)
new Vue({
  i18n,
  render: h => h(App)
}).$mount('#app')
